package com.dashboard.cloud.nacos.configure.controller;

import com.dashboard.cloud.common.module.APIResult;
import com.dashboard.cloud.nacos.configure.service.NacosRefreshConfigureService;
import com.dashboard.cloud.nacos.configure.service.NacosSimpleConfigureService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Properties;

/**
 * All rights Reserved, Designed By www.super-master.com
 *
 * @ProjectName: spring-cloud-dashboard
 * @Package: com.dashboard.cloud.nacos.configure.controller
 * @ClassName: NacosConfigureController
 * @Description: []
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2024/11/8 14:34
 * @Version: V1.0
 * @Copyright: 2024 www.super-master.com Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Slf4j
@RestController
@RequestMapping("/nacos/configure/")
public class NacosConfigureController {
    @Resource
    private NacosSimpleConfigureService nacosSimpleConfigureService;
    @Resource
    private NacosRefreshConfigureService nacosRefreshConfigureService;

    @PostMapping("/simple")
    public APIResult<Properties> getSimpleConfigureContent() {
        try {
            Properties properties = nacosSimpleConfigureService.obtainSimpleConfigure();
            return APIResult.success(properties);
        } catch (Exception e) {
            log.error("获取简单配置失败，", e);
            return APIResult.failure(e.getMessage());
        }
    }

    @PostMapping("/refresh")
    public APIResult<Properties> getRefreshConfigure() {
        try {
            Properties properties = nacosRefreshConfigureService.obtainRefreshConfigure();
            return APIResult.success(properties);
        } catch (Exception e) {
            log.error("获取实时配置失败，", e);
            return APIResult.failure(e.getMessage());
        }
    }

    @PostMapping("/module")
    public APIResult<Properties> getModuleConfigure() {
        try {
            Properties properties = nacosRefreshConfigureService.obtainModuleConfigure();
            return APIResult.success(properties);
        } catch (Exception e) {
            log.error("获取实时配置失败，", e);
            return APIResult.failure(e.getMessage());
        }
    }
}